package com.itheima.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    /**
     * 加载Spring的配置类
     */
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override
    /**
     * 加载springmvc的配置类
     */
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    @Override
    /**
     * 设置拦截路径
     */
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    //TODO:添加POST请求中文乱码过滤器
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");   //设置字符集
        //filter.setForceEncoding(true);  //强制使用指定的字符集
        return new Filter[]{filter};
    }
}
